<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<script type="text/javascript" src="jquery.min.js"></script>
</head>
<script type="text/javascript">
	function sub() {
		var username = $("#username").val();
		var password = $("#password").val();
		var data = {"username":username,"password":password};
		
		$.ajax({
			type:"post",
			url:"http://localhost:8081/sw_im/user/login",
			data:data,
			dataType: "json",
			success:function(msg){
				alert(msg[0].msg);
			},
			error:function(error){
				console.log(error);
			}
		});
	}
	
	function test() {
		 $.ajax({
			type:"get",
			url:"http://localhost:8081/sw_im/test/hello",
			dataType: "text",
			success:function(msg){
				
				alert(msg);
			},
			error:function(msg){
				console.log(msg);
			}
		});
	}
	function test1() {
		 $.ajax({
			type:"get",
			url:"http://localhost:8081/sw_im/test/say/你好",
			dataType: "json",
			success:function(msg){
				
				alert(msg.msg);
			},
			error:function(msg){
				console.log(msg.msg);
			}
		});
	}
	
	function test2() {
		$.ajax({
			type:"get",
			url:"http://localhost:8081/sw_im/test/person/3",
			dataType:"json",
			success:function(msg){
				alert(msg.name);
			}
		});
	}
	function test3() {
		$.ajax({
			type:"post",
			url:"http://localhost:8081/sw_im/address/add",
			data:{takeName:"李大帅",takePhone:"1254785668",addressInfo:"打发士大夫大师傅士大夫是",state:"1"},
			dataType:"json",
			success:function(msg){
				alert(msg.msg);
			}
		});
	}
	
	function sub1() {
		var id = $("#id").val();
		//var name = $("#id").val();
		$.ajax({
			type:"get",
			url:"http://localhost:8081/sw_im/module/selectById/"+id,
			dataType:"json",
			success:function(data){
				alert(data.name+","+data.id);
			}
		});
	}
	function sub2() {
		//var name = $("#id").val();
		$.ajax({
			type:"get",
			url:"http://localhost:8081/sw_im/module/selectModuleAll",
			dataType:"json",
			success:function(data){
				alert(data[1].id);
			}
		});
	}
	function insert() {
		var name = $("#name").val();
		var price = $("#price").val();
		var business = $("#business").val();
		$.ajax({
			type:"post",
			url:"http://localhost:8081/sw_im/module/add",
			data:{name:name,price:price,business:business},
			dataType:"json",
			success:function(data){
				alert(data.msg);
			}
		});
	}
</script>
<body>
	<div>
	 	用户名：<input type="text" id="username"/><br/>
	 	密&nbsp;码：<input type="text" id="password"/><br/>
	 	<input type="button" onclick="sub();" value="登录"/>
	</div>
	<div>
		<input type="button" onclick="test();" value="获取数据测试"/>
		<input type="button" onclick="test1();" value="say带参获取数据测试"/>
		<input type="button" onclick="test2();" value="带参获取数据测试"/>
		<input type="button" onclick="test3();" value="更新测试"/>
	</div>
	<div>
	 	id:<input type="text" id="id"/>
	 	<input type="button" onclick="sub1();" value="查询"/><br/>
	 	<input type="button" onclick="sub2();" value="查询全部"/>
	</div>
	<hr/>
	<div>
	 	name:<input type="text" id="name"/><br/>
	 	price:<input type="text" id="price"/><br/>
	 	business:<input type="text" id="business"/><br/>
	 	<input type="button" onclick="insert();" value="添加"/>
	</div>
</body>
</html>